package com.neutech.terrain;

import com.neutech.Util.ImageUtils;
import com.neutech.base.Drawable;
import com.neutech.base.Sprite;

import java.awt.*;
import java.util.ArrayList;
import java.util.List;

public class Water extends Sprite implements Drawable {
    private transient/*加上左面的是不被序列化的*/ List<Image> imageList = new ArrayList<>();

    public Water(int x, int y, int width, int height) {
        super(x, y, width, height);

        loadingImg();
    }
    private double index = 1;

    @Override
    public void draw(Graphics g) {
        if (imageList == null){
            imageList = new ArrayList<>();
            loadingImg();
        }
        /**
         * 减速器
         */
        index += 0.03;
        if (index > 2/*放在前面，先判断在绘制*/){
            index = 0;
        }
    g.drawImage(imageList.get((int) Math.floor(index)),getX(),getY(),null);


    }

    @Override
    public Rectangle getRectangle() {
        return new Rectangle(getX(),getY(),getWidth(),getHeight());
    }
    public void loadingImg(){
      imageList.add(ImageUtils.getValue("water1"));
      imageList.add(ImageUtils.getValue("water2"));

    }
}
